# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Alexander F Rødseth <xyproto@archlinux.org>
# Contributor: Bartłomiej Piotrowski <nospam@bpiotrowski.pl>
# Contributor: Robert Hollencamp <rhollencamp@gmail.com>
# Contributor: Daniel J Griffiths <griffithsdj@inbox.com>
# Contributor: Stefan Husmann <stefan-husmann@t-online.de>
# Contributor: Roman Mikhayloff <rimf@inbox.ru>

pkgname=codeblocks
pkgver=20.03
pkgrel=4
pkgdesc='Cross-platform C/C++ IDE'
arch=('loong64' 'x86_64')
url='http://codeblocks.org/'
license=('GPL3')
depends=('boost-libs' 'wxwidgets-gtk3' 'hunspell')
makedepends=('boost' 'imagemagick' 'zip')
source=("https://downloads.sourceforge.net/codeblocks/$pkgname-$pkgver.tar.xz"
         codeblocks-gcc11.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/40eb88e3f2b933f19f9933e06c8d0899c54f5e25.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/56ac0396fad7a5b4bbb40bb8c4b5fe1755078aef.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/a4aacc92640b587ad049cd6aa68c637e536e9ab5.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/f2f127cf5cd97c7da6a957a3f7764cb25cc9017e.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/04b7c50fb8c6a29b2d84579ee448d2498414d855.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/2345b020b862ec855038dd32a51ebb072647f28d.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/dbdf5c5ea9e3161233f0588a7616b7e4fedc7870.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/8035dfdff321754819f79e3165401aa59bd8c7f7.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/9a9c6a9d5e3e0f6eff5594ecd61a2222f073be9c.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/c28746f4887f10e6f9f10eeafae0fb22ecdbf9c7.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/b2e4f1279804e1d11b71bc75eeb37072c3589296.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/29315df024251850832583f73e67e515dae10830.patch
         https://github.com/arnholm/codeblocks_sfmirror/commit/46720043319758cb0e798eb23520063583c40eaa.patch 
         sc_wxtypes-normalize.patch)
sha256sums=('15eeb3e28aea054e1f38b0c7f4671b4d4d1116fd05f63c07aa95a91db89eaac5'
            '10b2b08440adc447d1d23eb122fa37beff1f26b9d7588b83f8435721586f4ed1'
            '0f9a3ae205afd358eeb643d5553f57f43cb0494c54ebd0a03f2c07d08df7713a'
            'fda1ed975756f8b12b8d84e91be890becaa0fcd3797fd7d36df393531f42f5ea'
            '520ee4ad5264d2a602c034259c3e47f768906f18fbc9a45c7102344345e17ebf'
            '4ab925d798922394ca28193b459515c6cd6f647629b867487eb9e4a40bbcc988'
            'b98ed0bfe926903ce16daea8b16973adfe97a3b8b12b628bc76b27e3fd1eccf5'
            '28e23c2e1d1fd22d47c9a8bc318cd80d96eee23e03d397e59d2bf775cb802db7'
            '2e62744218373cbba213f33eb4c473ac464dc8f3267253097fdf6ed39fedac0f'
            '29bb2bbe3262b5590567227f79fa2513570dd69102bb4932e8bb77dc4f087398'
            'cd12faec5678cf0c0906a3f7fe7cd09fc2eecf5b5fbb9d9ce7c6b6effd89af33'
            '309eb824493a36f5ad9b51bc29af77730a0cf8698f75584c95bdd16f22f3fc78'
            'c9723cac8ca690694b9db867b9b65736a1596958e153efd7672bf89ce832a6bd'
            '8a89646c875e2c4f39019a58c378531b3bbe5e0a21deb18f679a799da0e2321b'
            '5b80ef86fd6de408bfa77914cd5c6fc72c0f096bd40da0e02b376636cc18684d'
            'a4d39d3016fe128e521c38a23b7b25ce94ea18263498a60d6224729dee528564')

prepare() {
  cd $pkgname-$pkgver
  convert src/mime/codeblocks.png +set date:create +set date:modify -background none -extent 64x64 src/mime/codeblocks.png
  sed -i 's|$(datadir)/pixmaps|$(datadir)/icons/hicolor/64x64/apps|' src/mime/Makefile.{am,in}
  sed -i 's|$(datarootdir)/appdata|$(datarootdir)/metainfo|' Makefile.{am,in} src/plugins/contrib/appdata/Makefile.{am,in}

  patch -p1 < ../codeblocks-gcc11.patch # Fix build with GCC 11 (Fedora)
  patch -p1 < ../2345b020b862ec855038dd32a51ebb072647f28d.patch # Fix build with wxWidgets 3.2
  patch -p1 < ../40eb88e3f2b933f19f9933e06c8d0899c54f5e25.patch
  patch -p1 -F3 < ../56ac0396fad7a5b4bbb40bb8c4b5fe1755078aef.patch
  patch -p1 < ../a4aacc92640b587ad049cd6aa68c637e536e9ab5.patch
  patch -p1 < ../f2f127cf5cd97c7da6a957a3f7764cb25cc9017e.patch
  patch -p1 < ../dbdf5c5ea9e3161233f0588a7616b7e4fedc7870.patch
  patch -p1 < ../04b7c50fb8c6a29b2d84579ee448d2498414d855.patch
  patch -p1 < ../8035dfdff321754819f79e3165401aa59bd8c7f7.patch
  patch -p1 < ../9a9c6a9d5e3e0f6eff5594ecd61a2222f073be9c.patch
  patch -p1 < ../c28746f4887f10e6f9f10eeafae0fb22ecdbf9c7.patch
  patch -p1 < ../b2e4f1279804e1d11b71bc75eeb37072c3589296.patch
  patch -p1 < ../29315df024251850832583f73e67e515dae10830.patch
  patch -p1 < ../46720043319758cb0e798eb23520063583c40eaa.patch
  patch -p1 < ../sc_wxtypes-normalize.patch
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr --with-contrib-plugins=all,-FileManager
  sed -i 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
}
